import sys
from pathlib import Path

base_path = str(Path(__file__).resolve().parent.parent)
sys.path.append(base_path)
from langchain_community.document_loaders import TextLoader
from langchain_text_splitters import MarkdownHeaderTextSplitter

markdown_splitter = MarkdownHeaderTextSplitter(
    headers_to_split_on=[
        ("#", "一级标题"),
        ("##", "二级标题"),
        ("###", "三级标题"),
    ],
    strip_headers=True,
)


def get_markdown_text():
    with open(
        f"{base_path}/data/md_list/百炼_图像局部重绘.md", "r", encoding="utf-8"
    ) as fs:
        content = fs.read()
        return content


markdown_content = get_markdown_text()
lis = markdown_splitter.split_text(markdown_content)
for index, text in enumerate(lis):
    print(f"第{index}个文档\n")
    print(text)
    print("\n")
    print("-" * 50)
